home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / buttonbase / source / newimagebutton.e < prev   
Encoding:
Text File  |  1998-06-05  |  3.6 KB  |  107 lines

  1. /*
  2.    Name:      newimagebutton.e
  3.    About:     A subclass of the buttonbase Plugin for an imagebutton
  4.    Version:   1.0 (5.6.98)
  5.    Author:    Copyright © 1998 Victor Ducedre (victord@netrover.com)
  6.  
  7.    A brief note: This is an example of a subclass of buttonbase.  It supports
  8.    normal and selected images, and will set its size in the constructor to the
  9.    size of the normal image if no size parameters are specified.
  10.  
  11. */
  12. OPT MODULE
  13. OPT PREPROCESS
  14. OPT OSVERSION=37
  15.  
  16. MODULE 'tools/EasyGUI', 'tools/textlen', 'graphics/rastport',
  17.        'intuition/intuition', 'intuition/gadgetclass',
  18.        'gadgets/buttonclass', 'plugins/buttonbase',
  19.        'tools/ctype', 'utility', 'utility/tagitem'
  20.  
  21. CONST NB_GADGET=$FF010001   -> kept private, and defined in each subclass
  22.  
  23. -> define NEWIMAGEBUTTON to make EasyGUI's gadget list more readable!
  24. EXPORT CONST NEWIMAGEBUTTON=PLUGIN
  25.  
  26. EXPORT ENUM NIB_WIDTH=$FF010011,      -> [I.G]
  27.   NIB_HEIGHT,                         -> [I.G]
  28.   NIB_IMAGE,                          -> [IS.]
  29.   NIB_SELECTRENDER                    -> [IS.]
  30.  
  31. EXPORT OBJECT newimagebutton OF buttonbase PRIVATE
  32.   image:PTR TO image
  33.   selectimage:PTR TO image
  34.   width
  35.   height
  36. ENDOBJECT
  37.  
  38. PROC button(tags) OF newimagebutton
  39.   SUPER self.button(tags)
  40.   self.image:=      GetTagData(NIB_IMAGE, NIL, tags)
  41.   IF self.image=NIL THEN Raise("nbut")
  42.   self.selectimage:=GetTagData(NIB_SELECTRENDER, NIL, tags)
  43.   self.width:=      Max(self.image.width,  GetTagData(NIB_WIDTH,  NIL, tags))
  44.   self.height:=     Max(self.image.height, GetTagData(NIB_HEIGHT, NIL, tags))
  45. ENDPROC
  46.  
  47. PROC min_size(ta,fh) OF newimagebutton
  48. ENDPROC self.width+4, self.height+2
  49.  
  50. ->will_resize() - uses superclass method
  51.  
  52. PROC render(ta,x,y,xs,ys,w:PTR TO window) OF newimagebutton
  53. -> be sure to dynamically allocate your tag list with NEW;
  54. -> see buttonbase/settags() for more info
  55.   self.settags(NEW [GA_IMAGE,self.image,
  56.                     IF self.selectimage THEN GA_SELECTRENDER ELSE TAG_IGNORE, self.selectimage,
  57.                     GA_HIGHLIGHT, IF self.selectimage THEN GFLG_GADGHIMAGE ELSE GFLG_GADGHNONE,
  58.                     BUT_FILLPEN, w.rport.bgpen,
  59.                     NIL])
  60.   SUPER self.render(ta,x,y,xs,ys,w)
  61. ENDPROC
  62.  
  63. ->clear_render() - uses superclass method
  64.  
  65. PROC message_test(imsg:PTR TO intuimessage,win:PTR TO window) OF newimagebutton
  66. IF Not(SUPER self.get(NB_DISABLED))
  67.   IF imsg.class=IDCMP_GADGETUP THEN RETURN (imsg.iaddress=SUPER self.get(NB_GADGET))
  68. ENDIF
  69. ENDPROC FALSE
  70.  
  71. PROC message_action(class,qual,code,win:PTR TO window) OF newimagebutton
  72.   SUPER self.set(NB_SELECTED, code)
  73. -> Using SUPER here is only a time-saver; sending it to self.set() will work,
  74. -> since self.set() will eventually make this same call to the superclass
  75. ENDPROC TRUE
  76.  
  77. PROC set(attr, val) OF newimagebutton
  78. DEF image:PTR TO image
  79.   SELECT attr
  80.     -> Note:  for both NIB_IMAGE and NIB_SELECTRENDER, the image is only
  81.     -> accepted and changed if the width and height are <= those of the
  82.     -> initial image.  The gadget will not adjust its size.
  83.     CASE NIB_IMAGE
  84.       image:=val
  85.       IF (image.width<=self.width) AND (image.height<=self.height)
  86.         self.image:=image
  87.         SUPER self.set(NB_GADGET, [GA_IMAGE, image, NIL])
  88.       ENDIF
  89.     CASE NIB_SELECTRENDER
  90.       image:=val
  91.       IF (image.width<=self.width) AND (image.height<=self.height)
  92.         self.selectimage:=image
  93.         SUPER self.set(NB_GADGET, [GA_SELECTRENDER,image,NIL])
  94.       ENDIF
  95.     DEFAULT
  96.       SUPER self.set(attr, val)
  97.   ENDSELECT
  98. ENDPROC
  99.  
  100. PROC get(attr) OF newimagebutton
  101.   SELECT attr
  102.     CASE NIB_WIDTH;     RETURN self.width, TRUE
  103.     CASE NIB_HEIGHT;    RETURN self.height, TRUE
  104.   ENDSELECT
  105. ENDPROC SUPER self.get(attr)
  106.  
  107.